package com.fzy.core;

public class V {
	
	public static boolean required(Object value){
		if(value == null)
			return false;
		else if(value instanceof String && value.toString().trim().equals(""))
			return false;
		else
			return true;
	}
	
	public static boolean integer(String value){
		if(value != null && !value.trim().equals("")){
			try {
				Long.parseLong(value);
			} catch (NumberFormatException e) {
				return false;
			}
		}
		return true;
	}

	public static boolean maxLength(String value,int maxLength){
		if(value != null){
			int length = length(value);
			if(length > maxLength)
				return false;
		}
		return true;
	}

	public static boolean minLength(String value,int minLength){
		if(value != null){
			int length = length(value);
			if(length < minLength)
				return false;
		}else{
			return false;
		}
		return true;
	}
	
    public static int length(String value) {
        int valueLength = 0;
        for (int i = 0; i < value.length(); i++) {
            String temp = value.substring(i, i + 1);
            if (isAssic(temp)) {
                valueLength += 1;
            } else {
                valueLength += 2;
            }
        }
        return valueLength;
    }
    
    public static boolean isAssic(String src){
    	return src == null ? false : src.matches("[\u0000-\u00ff]+");
    }
}
